#!/usr/bin/env bash

# 安装软件环境,请参考此文档,仅仅只是参考啊!看见报错要当心

# bashrc
cd ~
echo "export CLICOLOR=1" >> .bashrc
echo "export LSCOLORS=gxfxcxdxbxegedabagacad" >> .bashrc
echo "export PS1='\[\033[01;32m\]\u @:\[\033[01;36m\]\w\[\033[00m\]\$ '" >> .bashrc
source .bashrc

# aliyun-mirrors
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://mirrors.aliyuncs.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyuncs.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list.d/aliyun_mirrors.list
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" >> /etc/apt/sources.list.d/pgdg.list
apt-get update

# 检查python版本
#python -V | grep

# 安装pip
#wget https://bootstrap.pypa.io/get-pip.py
#python get-pip.py
apt-get install python-pip
pip install -U pip
#pip install --upgrade ndg-httpsclient

cd ~
echo "export CLICOLOR=1
export LSCOLORS=gxfxcxdxbxegedabagacad
export PS1='\[\033[01;32m\]\u @:\[\033[01;36m\]\w\[\033[00m\]\$ '" >> .bashrc
###重启一下teminal

### 安装Scrapy
# 1.升级python至2.7.11(自带pip)
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar -xvf Python-2.7.11.tgz
cd Python-2.7.11
./configure && make && make install && make clean
# 2.安装依赖包
apt-get install python-dev libxml2-dev libxslt1-dev libssl-dev libffi-dev
# 3.安装scrapy
pip install Scrapy


###安装postgresql-9.4  mongodb-3.2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

apt-get install postgresql-9.4
apt-get install -y mongodb-org
apt-get install pgadmin3

###安装python包
apt-get install postgresql-server-dev
apt-get install python-mysqldb python-psycopg2
pip install pymongo redis
# 安装xlrd
wget https://pypi.python.org/packages/source/x/xlrd/xlrd-0.9.4.tar.gz
tar -xvf xlrd-0.9.4.tar.gz
cd xlrd-0.9.4
python setup.py install

# jieba分词
pip install jieba

# git
apt-get install git

# 修改postgres密码--------------------------------------------------------
su postgres # 输入管理员密码
psql
alter user postgres with password 'new password';

#允许postgresql 远程访问
# 修改成监听所有ip地址的连接请求，如下：
echo "listen_addresses = '*'" >> `find / -name postgresql.conf`
# 在末尾的地方添加一行，如下：
# TYPE  DATABASE    USER        ADDRESS       METHOD
echo "host    all     all     0.0.0.0/0   md5" >> `find / -name pg_hba.conf`
# postgresql 重启
/etc/init.d/postgresql restart

# mongodb--------------------------------------------------------
export LC_ALL=C
# 修改mongod.conf
mv /etc/mongod.conf /etc/mongod.conf.old
echo "# mongod.conf
# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
# network interfaces
net:
  port: 27017
#  bindIp: 127.0.0.1
processManagement:
   fork: true
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:" >> /etc/mongod.conf
# 启动mongod服务 no auth
mongod
# 创建admin
mongo
#use admin
#db.createUser({user:"root", pwd:"Bitfeng,123", roles:[{role:"userAdminAnyDatabase", db:"admin"}]})
#var schema = db.system.version.findOne({"_id" : "authSchema"})
#schema.currentVersion = 3
#db.system.version.save(schema)
#quit()

mongod --config /etc/mongod.conf --auth

#redis数据库配置 --------------------------------------------------------
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
tar -xvf redis-3.0.7.tar.gz
cd redis-3.0.7
make
#修改redis.conf
#绑定 本地,禁止远程访问
#bind 127.0.0.1
#关闭持久化
#save ""
##save 900 1
##save 300 10
##save 60 10000
#开启密码认证
#requirepass "my password"
#redis守护进程
src/redis-server redis.conf &

#scrapyd \ scrapy-redis



# pycharm

#安装jdk
#返回到Home目录
cd ~
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

#automatically set up the Java 8 environment variables
sudo apt-get install oracle-java8-set-default

#配置$JAVA_HOME 环境变量

#Find out the path of your Java installation:

sudo update-alternatives --config java
#如/usr/lib/jvm/java-8-oracle
#编辑/etc/environment文件
sudo nano /etc/environment
#加入如下一行
#   JAVA_HOME="/usr/lib/jvm/java-8-oracle"

# ctrl+o：保存    ctrl+x：退出
#安装PyCharm
#http://www.jetbrains.com/pycharm/download/#section=linux  下载pycharm
#cd进入解压后的pycharm所在的目录
cd pycharm-community-3.4.1/bin/
./pycharm.sh​